import { defineStore } from 'pinia';
import { messageFn } from '../../utils';

import {
    getHistoryMeterchangePageApi,//业务综合办理-换表记录分类
    getHistoryPredepositPageApi,//业务综合办理-预收款记录分类
    getHistoryUserinfochangePageApi,///业务综合办理-用户档案更改履历分页
} from '/@/api/comprehensive/historyRecord';

import { useLoading } from '/@/components/Loading';

const [openFullLoading, closeFullLoading] = useLoading({
    tip: '加载中...',
});


interface historyRecordFace {
    MeterchangeList: []; //换表记录分类列表结果
    PredepositList: [];//预收款记录结果
    UserinfoList: [];//用户档案更改履历列表结果
    total: number;
    MeterPageInfo: object;
    PredepositInfo: object;
    UserInfoInfo: object;
}

export const historyRecordStore = defineStore({
    id: 'historyRecord-state',
    state: (): historyRecordFace => ({
        MeterchangeList: [], //冲换表记录分类列表结果
        PredepositList: [], //预收款记录结果
        UserinfoList: [],//用户档案更改履历列表结果
        total: 0,//总页数
        MeterPageInfo: {
            //分页
            page_no: 1,
            page_size: 10,
        },
        PredepositInfo: {
            //分页
            page_no: 1,
            page_size: 10,
        },
        UserInfoInfo: {
            //分页
            page_no: 1,
            page_size: 10,
        },
    }),
    getters: {

    },
    actions: {
        setTotal(total: number) {
            console.log('setTotal----', total);
            //总页数
            this.total = total;
        },
        //设置换表记录分页
        setMeterPageInfo(pageParams: object) {
            this.MeterPageInfo = pageParams;
        },
        //设置预收款记录分页
        setPredepositInfo(pageParams: object) {
            this.PredepositInfo = pageParams;
        },
        //设置用户档案分页
        setUserInfoInfo(pageParams: object) {
            this.UserInfoInfo = pageParams;
        },
        //换表记录分类列表结果
        setMeterchangeList(recordList: []) {
            this.MeterchangeList = recordList;
        },
        //预收款记录结果
        setPredepositList(handleList: []) {
            this.PredepositList = handleList;
        },
        //用户档案更改履历列表结果
        setUserinfoListt(recordList: []) {
            this.UserinfoList = recordList;
        },

        /*
        * @description: MeterchangeList //冲换表记录分类列表结果
        */
        async getHistoryMeterchangePageAction(params: object) {
            openFullLoading();
            try {
                const  getHistoryMeterchangePage = await getHistoryMeterchangePageApi(params);
                if ( getHistoryMeterchangePage.code === 0) {
                    this.setMeterchangeList(getHistoryMeterchangePage.data);
                    return true;
                } else {
                    messageFn('error',  getHistoryMeterchangePage.msg);
                    return false;
                }
            } finally {
                closeFullLoading();
            }
        },

          /*
        * @description: PredepositList //预收款记录结果
        */
          async getHistoryPredepositPageAction(params: object) {
            openFullLoading();
            try {
                const  getHistoryPredepositPage = await getHistoryPredepositPageApi(params);
                if ( getHistoryPredepositPage.code === 0) {
                    this.setPredepositList(getHistoryPredepositPage.data);
                    return true;
                } else {
                    messageFn('error',  getHistoryPredepositPage.msg);
                    return false;
                }
            } finally {
                closeFullLoading();
            }
        },

          /*
        * @description: bookListApi //冲换表记录分类列表结果
        */
          async getHistoryUserinfochangePageApiAction(params: object) {
            openFullLoading();
            try {
                const  getHistoryUserinfochangePage = await getHistoryUserinfochangePageApi(params);
                if ( getHistoryUserinfochangePage.code === 0) {
                    this.setUserinfoListt(getHistoryUserinfochangePage.data);
                    return true;
                } else {
                    messageFn('error',  getHistoryUserinfochangePage.msg);
                    return false;
                }
            } finally {
                closeFullLoading();
            }
        },

        
    }
});
